<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
	<form class="form-horizontal business-form" id="credit-infoc">
		<div class="current-state-bno">
			<div class="submit-buttonleft">
				<button id="createlvsh" class="btn-danger-my btn  btn-success" type="button" onclick="createslvsRecord();">新增</button>
				<button id="updatelvsh" class="btn-danger-my btn  btn-primary" type="button" onclick="updateslvsRecord();">修改</button>
			</div>
		</div>
		<div class="business-manwife">律师函记录</div>
		<div class="business-padding" id="yqlshDiv">
			<table cellpadding="0" cellspacing="0" border="0"
				class="infor-table">
				<tr>
					<td align="right"><label class="control-label np">逾期次数：</label>
					</td>
					<td>
						<div class="control-div np" id="yuqiCount"></div>
					</td>

					<td align="right"><label class="control-label np">逾期金额：</label>
					</td>
					<td>
						<div class="control-div np" id="yuqiAmount"></div>
					</td>

				</tr>
				<tr>
					<td align="right"><label class="control-label np">快递单号：</label>
					</td>
					<td>
						<div class="control-div np" id="yuqiNo"></div> <input
						type="hidden" id="yuqiCompany" />
					</td>
				</tr>
			</table>
			<button class="btn dpbtn_red" type="button" onclick="queryKuaiDiStatus();">执行查询</button>
			<div class="content content-posi hidden">
				<article id="expressDetail"></article>
			</div>

		</div>
	</form>
	
	<%@include file="/jsp/comm_js_include.jsp"%>
	<script type="text/javascript">
	var createslvsRecordlayer;
    var createslvsRecord=function(){
    	createslvsRecordlayer=layer.open({
			  title:'新建律师函',
			  type: 1,
			  area: ['600px', '400px'], //宽高
			  content: $('#lvsrecord'),
		});
    }
    
    var lvssave=function(){
    	var lshId=$("#lshId").val();
    	var data={};
    	var url='${basePath}/DhOverdueLetterLawyersController/save';
    	data.noExpress=$("#noExpress").val();
    	data.busiId= $.getUrlData("busiId");
    	data.jbTime=$("#sendTime").val();
    	data.remarks=$("#lvshremarks").val();
    	data.cusId= $.getUrlData("cusId");
    	data.overdueId= $.getUrlData("overdueId");
    	if(lshId !=null && lshId !=""){
    		data.id=lshId;
    		url='${basePath}/DhOverdueLetterLawyersController/modify';
    	}
    	data.companyExpress=$('#companyExpress option:selected').val();
    	var validstatus = $("#commentForm").valid();
		if(validstatus){
        	$.dpAjax({
        		show:false,
	    		url:url,
    			data:data,
    			success: function(datas){
    				document.getElementById("yuqiNo").innerHTML=$("#noExpress").val();
					layer.msg('执行成功！', {icon: 6});
					layer.close(createslvsRecordlayer);
					layer.close(updateslvsRecordlayer);
					getLshDataInfo();
                }
	    	});
		}	
    }
    
    var queryKuaiDiStatus=function(){
    	var data={};
    	data.no= document.getElementById("yuqiNo").innerHTML;
    	data.companyExpress=$("#yuqiCompany").val();
//			data.no="441568318847";
		$.dpAjax({
			show:false,
    		url:'${basePath}/DhOverdueLetterLawyersController/queryKuaiDiStutus',
			data:data,
			success: function(datas){
				$('.content-posi').removeClass('hidden');
 				var result = datas.result;
 				var aliDeliverInfoDetails = result.aliDeliverInfoDetails;
 				$('#expressDetail').empty();
 				 var html = "";
 				 if(aliDeliverInfoDetails && aliDeliverInfoDetails.length > 0) {
 					var length = aliDeliverInfoDetails.length;
 					for(var i = 0; i < length; i++) {
     					 var aliDeliverInfoDetail = aliDeliverInfoDetails[i];
     					 var classT = '';
     					var classP = '';
     					 if((i == length - 1) && (!result.success)) {
     						classT = 'text-yellow';
     						classP = 'point-yellow';
     					 } else if((i == length - 1) && (result.success)) {
     						classT = 'text-green';
     						classP = 'point-green';
     					 }
     					html += '<section><span class="point-time ' + classP + '"></span><time datetime="'+aliDeliverInfoDetail.time +'">';
     					html += '<span ' + (classT != '' ? 'class="'+classT+'"' : '') + '>' + aliDeliverInfoDetail.time+'&nbsp;&nbsp;&nbsp;<span>' 
     					html += aliDeliverInfoDetail.week + '</span></time><aside><p class="things ' + classT + '">';
     					html += aliDeliverInfoDetail.context + '</p></aside></section>';
 					 }
 				 } else {
 					html = '<div class="faile-infor">运单信息获取失败！</div>'; 
 				 }
 				$('#expressDetail').html(html);
 				layer.msg('查询快递信息成功', {icon: 6,time:3000});
				return;
            }
    	});
    }
    
    var updateslvsRecordlayer;
    var updateslvsRecord=function(){
    	var data={};
    	data.busiId=$.getUrlData("busiId");
    	$.dpAjax({
    		show:false,
    		url:'${basePath}/DhOverdueLetterLawyersController/list',
			data:data,
			success: function(datas){
				  var data=datas.result.rows;
				  if(data.length>0){
					  $("#noExpress").val(data[0].noExpress);
					  var t1 = document.getElementById("companyExpress");   
		      	      for(i=0;i<t1.length;i++){//给select赋值  
		      	         if(data[0].companyExpress==t1.options[i].value){  
		      	             t1.options[i].selected=true  
		      	         }  
		      	      }
					  return;
				  }
            	}
    	});
    	updateslvsRecordlayer=layer.open({
			  title:'修改律师函',
			  type: 1,
			  area: ['600px', '400px'], //宽高
			  content: $('#lvsrecord'),
		});
    }
    
    var lvscancel=function(){
    	layer.closeAll();
    }
    
    var getLshDataInfo=function(){
    	var data={};
		data.busiId=$.getUrlData("busiId");
		$("#yuqiAmount").html($.getUrlData("amountRemainder"));
		$("#yuqiCount").html($.getUrlData("overdueCountTotalReal"));
		$("#yqAmount").val($.getUrlData("amountRemainder"));
		$("#yqCount").val($.getUrlData("overdueCountTotalReal"));
		$.dpAjax({
			show:false,
    		url:'${basePath}/DhOverdueLetterLawyersController/list',
			data:data,
			success: function(datas){
				  var data=datas.result.rows;
				  if(data.length>0){
					  $("#yqlshDiv").show();
					  $("#lshId").val(data[0].replaceId);
					  document.getElementById("yuqiNo").innerHTML=data[0].noExpress;
					  document.getElementById("yuqiCompany").value=data[0].companyExpress;
					  $("#lvshremarks").val(data[0].remarks);
					  $("#sendTime").val(data[0].jbTime);
					 // layer.msg('执行成功！', {icon: 6});
					  $("#createlvsh").hide();
					  $("#updatelvsh").show();
					  return;
				  }
            }
    	});
    }
	</script>